package com.hzh.blog.common.manager;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.hzh.blog.common.dao.IbatisEntityDao;
import com.hzh.blog.common.pager.Page;
import com.hzh.blog.common.pager.PropertyFilter;
import com.hzh.blog.vo.TreeData;

public abstract class AbstractCommonManager implements CommonManager {

	public final List<TreeData> getWholeTree() {
		//获得一级节点
		List<TreeData> treeByLevel = getTreeByLevel(1,null);
		for (Iterator<TreeData> iterator = treeByLevel.iterator(); iterator.hasNext();) {
			TreeData treeData = (TreeData) iterator.next();
//			treeData.setIsexpand(true);
			String id = treeData.getId();
			List<TreeData> treeByLevel2 = getTreeByLevel(2,id);//获得当前一级节点对应的二级节点
			treeData.setChildren(treeByLevel2);
			//迭代当前一级节点对应的二级节点
			for (Iterator<TreeData> iterator2 = treeByLevel2.iterator(); iterator2
					.hasNext();) {
				TreeData treeData2 = (TreeData) iterator2.next();
				String id2 = treeData2.getId();
				 List<TreeData> treeByLevel3 = getTreeByLevel(3,id2);//获得当前二级节点对应的三级几点
				 treeData2.setChildren(treeByLevel3);
			}
		}
		
		return treeByLevel;
	}

	public abstract List<TreeData> getTreeByLevel(int level, String param) ;

	public abstract List<TreeData> getBranch(String param) ;
	
	public Page findPagerObjectListByFilter(List<PropertyFilter> propertyFilters,Page page, Map<String, String> otherParam){
		
		return getEntityDao().findPagerObjectListByFilter(propertyFilters, page, otherParam);
	}

	public Page findPagerObjectListByFilter(List<PropertyFilter> propertyFilters,Page page, String suffix, Map<String, String> otherParam){
		
		return getEntityDao().findPagerObjectListByFilter(propertyFilters, page,suffix, otherParam);
	}
	
	public Page findPagerObjectListByFilter(List<PropertyFilter> propertyFilters,Page page){
		
		return getEntityDao().findPagerObjectListByFilter(propertyFilters, page);
	}
	
	/**
	 * 如果业务类需要使用默认的分页方法，请实现此方法，初始化entityDao
	 * @param entityDao
	 */
	public abstract IbatisEntityDao getEntityDao();
	
}
